#include"comm.hpp"
#include<iostream>
#include<cerrno>
#include<cstring>
#include<unistd.h>      
#include <fcntl.h>
#include<sys/types.h>
#include<sys/stat.h>

int main()
{
    // 1. 打开命名管道
    ssize_t wfd = open(fifo_name.c_str(), O_WRONLY);
    if(wfd <= 0)
    {
        std::cout << errno << ":" << strerror(errno) << std::endl;
        exit(-1);
    }
    // 2. 写入数据
    char buff[LEN];
    while(true)
    {
        std::cout << "请输入消息：";
        char* msg = fgets(buff, sizeof(buff), stdin);
        buff[strlen(buff)-1] = 0; // 去掉\n

        ssize_t n = write(wfd, buff, strlen(buff));
        if(n < 0)
        {
            perror("write");
            exit(-1);
        }
    }
    close(wfd);
    return 0;
}